<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户资料审核</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/layer/layer.js"></script>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			var tpl = $("#treeTableTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			var data = ${fns:toJson(list)}, ids = [], rootIds = [];
			for (var i=0; i<data.length; i++){
				ids.push(data[i].id);
			}
			ids = ',' + ids.join(',') + ',';
			for (var i=0; i<data.length; i++){
				if (ids.indexOf(','+data[i].parentId+',') == -1){
					if ((','+rootIds.join(',')+',').indexOf(','+data[i].parentId+',') == -1){
						rootIds.push(data[i].parentId);
					}
				}
			}
			for (var i=0; i<rootIds.length; i++){
				addRow("#treeTableList", tpl, data, rootIds[i], true);
			}
			$("#treeTable").treeTable({expandLevel : 5});
			
			$(".pic").click(function(){
            	var url=$(this).data("url");
            	//页面层
            	layer.open({
            	  type: 1,
            	  title:"资料大图",
            	  skin: 'layui-layer-rim', //加上边框
            	  area: ['300px', '400px'], //宽高
            	  content: '<img src="'+url+'"></img>'
            	});
            });
			$(".pass").click(function(){
				var that=$(this);
				var customPayId=$("#customPayId").val();
				if($("#treeTableList").find("tr").length>0&&$("#no_data").length>0){
					layer.confirm("用户尚未上传所需资料，该笔贷款无法通过审核",{ btn: ['向用户推送审核信息','取消'],offset: ['300px', '500px']},function () {
						$.ajax({
							type : "POST",  //提交方式
							url : "${ctx}/sys/loan/customPay/pushUnPassMsg",//路径
							data : {"customPayId":customPayId},//数据，这里使用的是Json格式进行传输
							success : function(data) {//返回数据根据结果进行相应的处理
								if(data){
									layer.alert("推送成功",{offset: ['300px', '500px']},function(){
										window.location.href="${ctx}/sys/loan/customPay";
									});
								}else{
									layer.alert("操作失败",{offset: ['300px', '500px']});
								}
							}
						});
					});
					return;
				}
				if($("#msg_wrap .msg-item").length>0){
					layer.confirm($("#msg_wrap div").text()+"，该笔贷款无法通过审核",{ btn: ['向用户推送审核信息','取消'],offset: ['300px', '500px']},function () {
						$.ajax({
							type : "POST",  //提交方式
							url : "${ctx}/sys/loan/customPay/pushUnPassMsg",//路径
							data : {"customPayId":customPayId},//数据，这里使用的是Json格式进行传输
							success : function(data) {//返回数据根据结果进行相应的处理
								if(data){
									layer.alert("推送成功",{offset: ['300px', '500px']},function(){
										window.location.href="${ctx}/sys/loan/customPay";
									});
								}else{
									layer.alert("操作失败",{offset: ['300px', '500px']});
								}
							}
						});
					});
					return;
				}

            	var loan_limit=$("#loan_limit").val();
            	//var service_charge=$("#service_charge").val();
            	if(!loan_limit){
            		layer.alert("请填写预估可贷款金额",{offset: ['300px', '500px']});
            		return;
            	}
            	/*if(!service_charge){
            		layer.alert("请填写订金",-1);
            		return;
            	}*/
            	var a=/^[0-9]*(\.[0-9]{1,2})?$/;
            	if(!a.test(loan_limit)){
					layer.alert("可贷款金额格式错误，请重新输入",{offset: ['300px', '500px']});
            		return false;
            	}
            	/*if(!a.test(service_charge)){
            		alert("订金格式错误，请重新输入");
            		return false;
            	}*/
            	 $.ajax({
                       type : "POST",  //提交方式  
                       url : "${ctx}/sys/loan/customPay/passLoan",//路径  
                       data : {"customPayId":customPayId,"loanLimit":loan_limit},//数据，这里使用的是Json格式进行传输
                       success : function(data) {//返回数据根据结果进行相应的处理  
                            if(data){
                            	layer.alert("操作成功,该贷款已审批通过，目前状态为<span style='color:green'>【结算】</span>",{offset: ['300px', '500px']},function(){
                            		window.location.href="${ctx}/sys/loan/customPay";
                            	});
                            }else{
                            	layer.alert("操作失败",{offset: ['300px', '500px']});
                            }
                       }  
                 });  
			});
		});
		function addRow(list, tpl, data, pid, root){
			for (var i=0; i<data.length; i++){
				var row = data[i];
				if ((${fns:jsGetVal('row.parentId')}) == pid){
					$(list).append(Mustache.render(tpl, {
						dict: {
						blank123:0}, pid: (root?0:pid), row: row
					}));
					addRow(list, tpl, data, row.id);
				}
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li ><a href="${ctx}/sys/loan/customPay/">客户申请记录列表</a></li>
		<li class="active"><a >审批贷款</a></li>
	</ul><br/>
		<div class="container">
		<input type="hidden" id="customPayId" value="${customPayId}" />
		<%--	<c:when test="${empty muList && fn:length(muList)==0 }">
			<div class="col-md-2 col-md-offset-5" style="text-align: center;font-size:32px; line-height:550px; height: 550px;">
				该用户暂无上传资料 </div>
			</c:when>--%>
				<div class="row">
					<div id="left" style="width: 30%">
						<div class="col-md-2 col-md-offset-5" style="text-align: center;">
							<h1 id="member_h1" >${loan.name}所需资料<span style="color:red; font-size: 10px;"></span></h1>
					    </div>
					    <table id="treeTable" class="table table-striped table-bordered table-condensed">
							<thead>
								<tr>
									<th>名称</th>
								</tr>
							</thead>
							<tbody id="treeTableList"></tbody>
						</table>
					</div>
					<div  style="width: 68%;float: right;">
						<div class="col-md-2 col-md-offset-5" style="text-align: center;">
							<h1 id="member_h2" data-id="${member.id}">${member.nickname}的资料列表<span style="color:red; font-size: 10px;">(标绿部分为所必须的资料)</span></h1>
					    </div>
						<table class="table table-striped table-bordered table-condensed">
							  <thead>
							    <tr>
							   	  <th>所属资料</th>
							  	  <th>资料类别名</th>
							  	  <th>资料值</th>
							      <th>是否清晰</th>
							    </tr>
							  </thead>
							  <tbody>
							  <c:choose>
								  <c:when test="${empty groupMap && fn:length(groupMap)==0 }">
									<tr>
										<td colspan="5" id="no_data">该用户暂无上传资料 </td>
									</tr>

								  </c:when>
								  <c:otherwise>
									  <c:forEach items="${groupMap}" var="item" varStatus="statuss">
										  <c:forEach items="${item.value}" var="mu">
											  <c:if test="${mu.typeId !='1'}">
												  <tr>
													  <td>${mu.parentTypeName}<span style="color: #204a5a">[${mu.groupIndex}]</span> </td>
													  <td><span <c:if test="${mu.isLoanNeedMaterial==true}">style='color:green;'</c:if>>${mu.typeName}</span>  </td>
													  <td>
														  <c:choose>
															  <c:when test="${empty mu.url}">${mu.value}</c:when>
															  <c:otherwise>
																  <a class="pic" href="javascript:void(0)" data-url="${mu.url}"><img alt="资料图片" src="${mu.url}"   style="width: 50px;height: 50px;"></a>
															  </c:otherwise>
														  </c:choose>
													  </td>
													  <td>
														  <c:choose>
															  <c:when test="${empty mu.url}"><span style="color:blue">不是图片类型</span></c:when>
															  <c:when test="${empty mu.isClear}"><span style="color:red">未审核</span></c:when>
															  <c:when test="${mu.isClear==true}"><span style="color:green">已审核为：清晰</span></c:when>
															  <c:when test="${mu.isClear==false}"><span style="color:red">已审核为：不清晰</span></c:when>
															  <c:otherwise></c:otherwise>
														  </c:choose>
													  </td>
												  </tr>
											  </c:if>
										  </c:forEach>
									  </c:forEach>
								  </c:otherwise>
							  </c:choose>
							  </tbody>
							</table>
						<%-- 	<div>
							${loan.name}所需资料为：
							<c:forEach items="${list}" var="obj">
									 <c:choose>
									  <c:when test="${obj.parentId=='0'}">${obj.name}:</c:when>
									  <c:otherwise>
									  【${obj.name}】,
									  </c:otherwise>
									</c:choose> 
							</c:forEach>
							</div> --%>
							<div class="row" id="msg_wrap">
								系统审核信息：
								<div class="col-md-2 col-md-offset-5" style="text-align: left;">

									<c:forEach items="${msgList}" var="msg">
										<h2 style="color: red" class="msg-item">${msg}</h2>
									</c:forEach>
								</div>
							</div>
							<div class="row">
								<div class="col-md-2 col-md-offset-5" style="text-align: center;">
								预估可贷款金额为：<input type="text" style="height: 30px" placeholder="请输入预估可贷款金额（元）" id="loan_limit">
								<%--订金为：<input type="text" placeholder="请输入订金（元）" id="service_charge">--%>
							</div>
							<div class="row">
							<div class="col-md-2 col-md-offset-5" style="text-align: center;">
								<shiro:hasPermission name="sys:member:member:edit">
								<input id="btnSubmit" class="btn btn-danger pass" data-status="1"  value="审批该贷款为通过"/>
								</shiro:hasPermission>
								<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
						    </div>
						</div>
					</div>
					</div>
		</div>
		${msg}
	<script type="text/template" id="treeTableTpl">
		<tr id="{{row.id}}" pId="{{pid}}">
			<td><a href="javascript:void(0)">
			<span>
				{{row.name}}
			</span>
			</a></td>
		</tr>
	</script>
</body>
</html>